package com.maozzi.service.acl.domain.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maozzi.service.acl.domain.RoleDomainService;
import com.maozzi.service.acl.repository.mapper.RoleMapper;
import com.maozzi.service.acl.repository.model.Role;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 权限 - 角色 domain service
 *
 * @author maozi
 */
@Service
public class RoleDomainServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleDomainService {

    @Resource
    private RoleMapper roleMapper;

    @Override
    public Role getRole(Long roleId) {
        return roleMapper.selectById(roleId);
    }

    @Override
    public Role putRole(Role role) {
        role.setId(null);
        role.setCreateDate(null);
        role.setModifiedBy(null);
        role.setModifiedDate(null);
        role.setDeleted(null);
        roleMapper.insert(role);
        return role;
    }

    @Override
    public Boolean editRole(Long roleId, Role role) {
        role.setModifiedDate(null);

        return roleMapper.update(role, Wrappers.lambdaUpdate(Role.class).eq(Role::getId, roleId)) > 0;
    }

    @Override
    public Page<Role> rolePage(Page<Role> page, Wrapper<Role> query) {
        return roleMapper.selectPage(page, query);
    }
}
